package com.example.youhuo.network

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class NetWorkManager private constructor(){
    var retrofit: Retrofit? = null
    init {
        var okBuilder:OkHttpClient.Builder = OkHttpClient.Builder()
        okBuilder.readTimeout(30*1000,TimeUnit.MILLISECONDS)
        okBuilder.writeTimeout(30*1000,TimeUnit.MILLISECONDS)
        okBuilder.connectTimeout(30*1000,TimeUnit.MILLISECONDS)

        okBuilder.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))

        var builder:Retrofit.Builder = Retrofit.Builder()
        builder.baseUrl(Api.baseUrl)
        builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        builder.addConverterFactory(GsonConverterFactory.create())
        retrofit = builder.build()






    }

    companion object{
        val instance: NetWorkManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            NetWorkManager()
        }


    }
}